//
//  ShangpinqingdanViewController.m
//  tianjin
//
//  Created by 鞠超 on 16/8/11.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "ShangpinqingdanViewController.h"

#import "ShangpinqingdanTableViewCell.h"
#import "ChanpinxiangqingViewController.h"

@interface ShangpinqingdanViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;
//头视图
@property (nonatomic, strong) UIView * view_headBg;

@end

@implementation ShangpinqingdanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void)p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    _topView.backgroundColor = [UIColor blackColor];
    
    _lblTitle.text = @"商品清单";
    _lblTitle.textColor = [UIColor whiteColor];
    _lblTitle.font = [UIFont systemFontOfSize:19];
    
    UIImageView * image_return = [[UIImageView alloc] initWithFrame:CGRectMake(15, 32, 10, 20)];
    image_return.image = [UIImage imageNamed:@"zuofanhui@2x.png"];
    [_topView addSubview:image_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 20, 35, 44);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableFooterView = [[UIView alloc] init];
    //头视图
    [self p_headView];
    self.tableView.tableHeaderView = self.view_headBg;
    
    [self.view addSubview:self.tableView];
    
    //注册
    [self.tableView registerClass:[ShangpinqingdanTableViewCell class] forCellReuseIdentifier:@"cell_qingdan"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
}

- (UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ShangpinqingdanTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_qingdan" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ChanpinxiangqingViewController * chanpinxiangqingViewController = [[ChanpinxiangqingViewController alloc] init];
    [self showViewController:chanpinxiangqingViewController sender:nil];
}

#pragma mark - 头视图
- (void )p_headView
{
    self.view_headBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    self.view_headBg.backgroundColor = [UIColor whiteColor];
    
    UIImageView * image_dianpu = [[UIImageView alloc] initWithFrame:CGRectMake(10, 12.5, 25, 25)];
    image_dianpu.image = [UIImage imageNamed:@"dianpu@2x.png"];
    [self.view_headBg addSubview:image_dianpu];
    
    UILabel * detail = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_dianpu.frame) + 10, 15, SCREEN_WIDTH - CGRectGetMaxX(image_dianpu.frame) - 20, 20)];
    detail.text = @"本APP所有商品由千金商城统一配送";
    detail.font = [UIFont systemFontOfSize:14];
    detail.textColor = navi_bar_bg_color;
    [self.view_headBg addSubview:detail];
    
    UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(0, 49, SCREEN_WIDTH, 1)];
    view_line.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view_headBg addSubview:view_line];
}















@end
